home *** CD-ROM | disk | FTP | other *** search
- Path: blv-pm12-ip6.halcyon.com!user
- From: hawkfish@punchdeck.com (Richard Wesley)
- Newsgroups: comp.lang.c++
- Subject: Re: STL Implementation
- Date: Wed, 27 Mar 1996 08:48:14 -0800
- Organization: Electric Fish, Inc.
- Message-ID: <hawkfish-2703960848140001@blv-pm12-ip6.halcyon.com>
- References: <3158429C.242F@cgsd.com>
- NNTP-Posting-Host: blv-pm12-ip6.halcyon.com
- X-Newsreader: Yet Another NewsWatcher 2.1.2
-
- In article <3158429C.242F@cgsd.com>, mckenna@cgsd.com wrote:
-
- >In C++ I can make a class with a pointer
- >to a member of that same class.
- >
- > class foo
- > {
- > int a;
- > foo * child;
- > };
- >
- >With STL I would like my class to have a point to a list
- >of objects in this class.
- >
- > class foo
- > {
- > int a;
- > list<foo> * child_list;
- > };
- >
- >But the pointer to the list<foo> can not be constructed
- >because foo isn't finished being defined yet.
- >
- >Is there a work around for this? Is there some other
- >implementation that I should be considering.
-
- Try
-
- list<foo*> child_list;
-
- The list will then be automatically created and deleted with foo objects
- and you can manipulate the child list without doing deep copies all over
- the place.
-
- Where the references get hairy is when you start using smart pointers
- instead of dumb ones (like foo *). Then you might want to use the
- Composite pattern and have the child list in multi_foo derived class.
-
-
- - rmgw
-
- http://www.halcyon.com/hawkfish/Index.html
-
- ----------------------------------------------------------------------------
- Richard Wesley | "I don't know about your dreams
- hawkfish@punchdeck.com | But mine are sort of hackneyed"
- hawkfish@electricfish.com | - Laurie Anderson, "Talk Normal"
- ----------------------------------------------------------------------------
-